package com.coder.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.coder.entity.CollLib;
import com.coder.mapper.CollMapper;
import com.coder.service.CollService;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * @author 王令
 */
@Service
public class CollServiceImpl extends ServiceImpl<CollMapper, CollLib> implements CollService {
    @Override
    public Map<String, Object> collInfo() {
        Map<String, Object> map = new HashMap<>();
        List<String> address = new ArrayList<>();
        List<String> colType = new ArrayList<>();
        list(new QueryWrapper<CollLib>().select("distinct address")).forEach(v -> {
            address.add(v.getAddress());
        });
        list(new QueryWrapper<CollLib>().select("distinct col_type")).forEach(v -> {
            colType.add(v.getColType());
        });
        map.put("address", address);
        map.put("colType", colType);
        return map;
    }

    @Override
    public IPage<CollLib> pageList(Page<CollLib> page, CollLib collLib) {
        LambdaQueryWrapper<CollLib> wrapper = new LambdaQueryWrapper<>();
        wrapper.select(CollLib::getId, CollLib::getColleges, CollLib::getAddress, CollLib::getColType, CollLib::getLevel,CollLib::getSupDepart , CollLib::getTopCol, CollLib::getTopSub, CollLib::getSatisfaction)
                .like(StrUtil.isNotBlank(collLib.getColleges()), CollLib::getColleges, collLib.getColleges())
                .like(StrUtil.isNotBlank(collLib.getAddress()), CollLib::getAddress, collLib.getAddress())
                .like(StrUtil.isNotBlank(collLib.getColType()), CollLib::getColType, collLib.getColType())
                .like(StrUtil.isNotBlank(collLib.getLevel()), CollLib::getLevel, collLib.getLevel());
        return page(page, wrapper);
    }

}
